﻿using System;
using System.Collections.Generic;
using System.Text;

namespace lxwmvc
{
    using System;
    using System.Xml;
    using System.Web;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Dynamic;
    /// <summary>
    /// 定义全局变量
    /// </summary>
    public class globalhelper
    {
        string _domain = "";
        int _expires_second = 0;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="expires_second"></param>
        public globalhelper(string domain = "",int expires_second = 0)
        {
            _domain = domain;
            _expires_second = expires_second;
        }

        /// <summary>
        /// 添加内容
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string this[string key]
        {
            get
            {
                if (HttpContext.Current.Session[key] != null)
                    return HttpContext.Current.Session[key].tostr();
                return cookieshelper.getcookie(key, _domain).tostr();
            }
            set
            {
                HttpContext.Current.Session[key] = value.tostr();
                cookieshelper.setcookie(key, value.ToString(), _domain, _expires_second);
            }
        }
    }
}